<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增角色信息')" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-juese-add">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">角色名称：</label>
                    <div class="col-sm-8">
                        <input name="roleName" id="roleName" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">权限字符：</label>
                    <div class="col-sm-8">
                        <input name="roleKey" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">显示顺序：</label>
                    <div class="col-sm-8">
                        <input name="roleSort" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
<!--            <div class="col-xs-12">-->
<!--                <div class="form-group">-->
<!--                    <label class="col-sm-3 control-label">数据范围：</label>-->
<!--                    <div class="col-sm-8">-->
<!--                        <input name="dataScope" class="form-control" type="text">-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
<!--            <div class="col-xs-12">-->
<!--                <div class="form-group">-->
<!--                    <label class="col-sm-3 control-label">菜单树选择项是否关联显示：</label>-->
<!--                    <div class="col-sm-8">-->
<!--                        <input name="menuCheckStrictly" class="form-control" type="text">-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
<!--            <div class="col-xs-12">-->
<!--                <div class="form-group">-->
<!--                    <label class="col-sm-3 control-label">部门树选择项是否关联显示：</label>-->
<!--                    <div class="col-sm-8">-->
<!--                        <input name="deptCheckStrictly" class="form-control" type="text">-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
<!--            <div class="col-xs-12">-->
<!--                <div class="form-group">-->
<!--                    <label class="col-sm-3 control-label">删除标志：</label>-->
<!--                    <div class="col-sm-8">-->
<!--                        <input name="delFlag" class="form-control" type="text">-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <label class="toggle-switch switch-solid">
                        <input type="checkbox" id="status" checked>
                        <span></span>
                    </label>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">备注：</label>
                    <div class="col-sm-8">
                        <textarea name="remark" class="form-control"></textarea>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">菜单权限：</label>
                <div class="col-sm-8">
                    <label class="check-box">
                        <input type="checkbox" value="1">展开/折叠</label>
                    <label class="check-box">
                        <input type="checkbox" value="2">全选/全不选</label>
                    <label class="check-box">
                        <input type="checkbox" value="3" checked>父子联动</label>
                    <div id="menuTrees" class="ztree ztree-border"></div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
        $(function() {
            var url = ctx + "sxt/caidan/roleMenuTreeData";
            var options = {
                id: "menuTrees",
                url: url,
                check: { enable: true },
                expandLevel: 0
            };
            $.tree.init(options);
        });
        var prefix = ctx + "sxt/juese"
        $("#form-juese-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var data = $("#form-juese-add").serializeArray();
                var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
                var menuIds = $.tree.getCheckedNodes();
                data.push({"name": "status", "value": status});
                data.push({"name": "menuIds", "value": menuIds});
                $.operate.save(prefix + "/add", data);
                //$.operate.save(prefix + "/add", $('#form-juese-add').serialize());
            }
        }

        $('input').on('ifChanged', function(obj){
            var type = $(this).val();
            var checked = obj.currentTarget.checked;
            if (type == 1) {
                if (checked) {
                    $._tree.expandAll(true);
                } else {
                    $._tree.expandAll(false);
                }
            } else if (type == "2") {
                if (checked) {
                    $._tree.checkAllNodes(true);
                } else {
                    $._tree.checkAllNodes(false);
                }
            } else if (type == "3") {
                if (checked) {
                    $._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
                } else {
                    $._tree.setting.check.chkboxType = { "Y": "", "N": "" };
                }
            }
        })
    </script>
</body>
</html>